home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * (a) (C) 1990 by Adobe Systems Incorporated. All rights reserved.
- *
- * (b) If this Sample Code is distributed as part of the Display PostScript
- * System Software Development Kit from Adobe Systems Incorporated,
- * then this copy is designated as Development Software and its use is
- * subject to the terms of the License Agreement attached to such Kit.
- *
- * (c) If this Sample Code is distributed independently, then the following
- * terms apply:
- *
- * (d) This file may be freely copied and redistributed as long as:
- * 1) Parts (a), (d), (e) and (f) continue to be included in the file,
- * 2) If the file has been modified in any way, a notice of such
- * modification is conspicuously indicated.
- *
- * (e) PostScript, Display PostScript, and Adobe are registered trademarks of
- * Adobe Systems Incorporated.
- *
- * (f) THE INFORMATION BELOW IS FURNISHED AS IS, IS SUBJECT TO
- * CHANGE WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED
- * AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
- * ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY
- * OR LIABILITY FOR ANY ERRORS OR INACCURACIES, MAKES NO
- * WARRANTY OF ANY KIND (EXPRESS, IMPLIED OR STATUTORY)
- * WITH RESPECT TO THIS INFORMATION, AND EXPRESSLY
- * DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR PARTICULAR PURPOSES AND NONINFRINGEMENT
- * OF THIRD PARTY RIGHTS.
- */
-
- /*
- * PSWpatternsdemo.psw
- *
- * These PostScript procedures are for the demonstration program only.
- * They are not the recommended approach for displaying patterns. The
- * font approach outlined in PSWpatterns.psw should be used instead.
- *
- * The composite method is not recommended because it is not much
- * faster than the font approach, it is difficult to work with and it will not
- * print. The drawing approach is not recommended because it is slow.
- *
- * Version: 2.0
- * Author: Ken Fromm
- * History:
- * 03-07-91 Added this comment.
- */
-
- defineps PSWPatternDemoDefs ()
-
- %
- % This dictionary is for using the composite method of pattern display.
- % It is fast provided the cell is not skewed. Only one pass is needed
- % even for colored patterns. Problems arise though in trying to tile
- % up the patterns. Plus this approach won't print.
- %
- /PatternImageDict
- 8 dict begin
-
- /PATImageDict 1 dict def
-
- % PATsi - sets the image in the dictionary
- /PATsi { % gstate PATsi -
- PATImageDict /CurrentImage 3 -1 roll put
- } bind def
-
- /PATdrawcell {
- newpath
- BBox aload pop
- 2 index sub exch
- 3 index sub exch
- PATrectdraw
- } bind def
-
- /PATsize { % patdict PATsize x y w h
- begin
- gsave
- matrix currentmatrix % matrix
- PatternGState PATsg
- PATdrawcell
- setmatrix % -
-
- pathbbox % llx lly urx ury
- 2 index sub exch % llx lly h urx
- 3 index sub exch % llx lly w h
- grestore
- end
- } bind def
-
- % PATpicalc - calculates the starting point and width/height of the tile fill for the shape
- /PATpicalc { % - PATpicalc nw nh px py
- PATDict /CurrentPattern get begin
- pathbbox % llx lly urx ury
-
- % Determine (nw, nh) the number of cells to paint width and height
- PatHeight div ceiling 1 add % llx lly urx qh
- 4 1 roll % qh llx lly urx
- PatWidth div ceiling 1 add % qh llx lly qw
- 4 1 roll % qw qh llx lly
- PatHeight div floor % qw qh llx ph
- 4 1 roll % ph qw qh llx
- PatWidth div floor % ph qw qh pw
- 4 1 roll % pw ph qw qh
- 2 index sub cvi abs % pw ph qw qh-ph
- exch 3 index sub cvi abs exch % pw ph nw=qw-pw nh=qh-ph
-
- % Determine the starting point of the pattern fill (px, py)
- 4 2 roll % nw nh pw ph
- PatHeight mul PatHeight sub % nw nh pw py
- exch % nw nh py pw
- PatWidth mul PatWidth sub % nw nh py px
- exch % nw nh px py
- end
- } bind def
-
- % PATtile - performs the tiling for the shape
- /PATtile { % nw nh px py PATtile -
- PATDict /CurrentPattern get dup begin
- setfont
-
- matrix currentmatrix
- PatternGState PATsg % but keep the same matrix
- setmatrix
-
- PaintType 2 eq { PATDict /PColor get PATsc } if
-
- 0 1 NumSources 1 sub { % nw nh px py source
- 2 index 2 index % nw nh px py source px py
- moveto % nw nh px py source
-
- Multi { dup PaintColors exch get PATsc } if
-
- 0 1 PATfstr length 1 sub { 1 index PATfstr 3 1 roll put } for pop
- 2 index % nw nh px py nh
- { % nw nh px py
- currentpoint
- 5 index % nw nh px py cx cy nw
- { % nw nh px py
- PATfstr oldshow
- } repeat
- YStep add moveto
- } repeat
- } for
- pop pop pop pop
- end
- } bind def
-
- /PATimage{ % patdict PATimage gstate
- begin
- gsave
- currentdict PATsize % x y w h
- 4 2 roll pop pop % w h
- transform % w' h'
- PatternGState PATsg
- itransform translate % -
-
- gsave
- PATdrawcell
- PATpicalc % nw nh px py
- clip
- newpath
- PATtile % -
- grestore
- gstate currentgstate % gstate
- grestore
- end
- } bind def
-
- % PATfill - performs the tiling for the shape
- /PATfill { % nw nh px py PATfill -
- PATDict /CurrentPattern get begin
-
- % Set up the coordinate system to Pattern Space
- PatternGState PATsg
-
- % Translate so that the compositing places the cell correctly
- BBox 0 get BBox 1 get translate
-
- % Move to the starting location
- moveto % nw nh
-
- BBox aload pop % nw nh llx lly urx ury
- 2 index sub exch % nw nh llx lly h urx
- 3 index sub exch % nw nh llx lly w h
- 4 index % nw nh llx lly w h nh
- { % nw nh llx lly w h
- currentpoint % nw nh llx lly w h cx cy
- 6 2 roll % nw nh cx cy llx lly w h
- 7 index % nw nh cx cy llx lly w h nw
- { % nw nh cx cy llx lly w h
- 4 copy
- PATImageDict /CurrentImage get
- currentpoint 1 composite % -
- XStep 0 rmoveto
- } repeat
- 6 -2 roll moveto
- 0 YStep rmoveto
- } repeat
- pop pop pop pop pop pop
- end
- } bind def
-
- currentdict
- end
- def
-
- %
- % Do not use this method. It is much slower than the font and composite
- % approaches. The font method takes advantage of the font cache. This
- % method draws each cell each time. It takes a long time to display which
- % means it would take FOREVER to print a pattern this way.
- %
- /PatternDrawDict
- 1 dict begin
-
- % PATfill - performs the tiling for the shape
- /PATfill { % nw nh px py PATfill -
- false PATredef
- PATDict /CurrentPattern get begin
-
- % Set up the coordinate system to Pattern Space
- PatternGState PATsg
-
- % Set the color for uncolored patterns
- PaintType 2 eq { PATDict /PColor get PATsc } if
-
- % Loop for each of the pattern sources
- 0 1 NumSources 1 sub { % nw nh px py source
- % Move to the starting location
- 2 index 2 index % nw nh px py source px py
- moveto % nw nh px py source
-
- % For multiple sources, set the appropriate color
- Multi { dup PaintColors exch get PATsc } if
-
- Multi { PaintData exch get } if % nw nh px py [paintdata]
- currentdict % nw nh px py [paintdata] dict
-
- % Loop over the number of vertical cells
- 4 index % nw nh px py [paintdata] dict nh
- { % nw nh px py [paintdata] dict
- % Loop over the number of horizontal cells
- currentpoint
- 7 index % nw nh px py [paintdata] dict cx cy nw
- { % nw nh px py [paintdata] dict cx cy
- gsave
- currentpoint translate
- mark % nw nh px py [paintdata] dict cx cy mark
- 4 index % nw nh px py [paintdata] dict cx cy mark [paintdata]
- 4 index % nw nh px py [paintdata] dict cx cy mark [paintdata] dict
- PaintProc % nw nh px py [paintdata] dict cx cy mark
- cleartomark % nw nh px py [paintdata] dict cx cy
- grestore
- XStep 0 rmoveto
- } repeat
- YStep add moveto
- } repeat pop pop
- } for
- pop pop pop pop
- end
- true PATredef
- } bind def
-
- currentdict
- end
- def
-
- endps
-
- /*****************************************************
- *
- * The wraps called from the pattern object.
- *
- *****************************************************/
-
- defineps PSWBeginPatternImage()
- PatternImageDict begin
- endps
-
- defineps PSWSetPatternImage(userobject PatternImageNum)
- PatternImageNum PATsi
- endps
-
- /*
- * Sizes the image for the pattern in the current window. Assumes the
- * PatternDict is already on the dictionary stack.
- */
- defineps PSWSizeImage(userobject PatternNum | float *X, *Y, *W, *H)
- PatternNum PATsp
- PatternImageDict begin
- PatternNum PATsize H W Y X
- end
- PATusp
- endps
-
- /*
- * Make an image of the pattern in the current window. The image
- * will be composited into the clipping path to produce the pattern.
- * Leaves a gstate object on the stack. Assumes the PatternDict is
- * already on the dictionary stack.
- */
- defineps PSWMakeImage(userobject PatternNum)
- PatternNum PATsp
- PatternImageDict begin
- PatternNum PATimage
- end
- PATusp
- endps
-
-
- defineps PSWBeginPatternDraw()
- PatternDrawDict begin
- endps
-
-
- defineps PSWCompositePattern(userobject PatternNum, PatternImageNum; float X, Y)
- PatternNum begin
- BBox aload pop % llx lly urx ury
- 2 index sub exch % lx lly h urx
- 3 index sub exch % llx lly w h
- 2 copy PatternGState /cm get % llx lly w h matrix
- dtransform % llx lly w h w' h'
- idtransform % llx lly w h w* h*
- Y exch 2 div sub exch % llx lly w h y* w*
- X exch 2 div sub exch % llx lly w h x* y*
- PatternImageNum 3 1 roll % llx lly w h gstate x* y*
- 1 composite % -
- end
- endps
-